<?php

if ($_POST) {
	$errors = array();
	if (!$_POST['range']['title']) $errors[] = 'TITLE';
	elseif ($db->fetchOne("SELECT id FROM shop_ranges WHERE title=?", $_POST['range']['title'])) $errors[] = 'TITLE_UNIQUE';
	
	if (sizeof($errors)) {
		$smarty->assign('errors', $errors);
	} else {
		$smarty->assign('success', true);
		$db->insert('shop_ranges', array_merge(array('site_id' => $site['id']), $_POST['range']));
		$smarty->assign('range_id', $db->lastInsertId());
		
		
	}
	
}



$smarty->assign('custom_templates_dir', $app_root . $site['home_dir'] . '/admin-custom/templates');
if (is_xhr()) {
	header('Content-type: text/xml');
	$smarty->display('shop/ranges/_edit_messages.tpl.taconite');
} else {
	$smarty->display('shop/ranges/edit.tpl.html');
}